/**
 * Author: jinchao
 * Copyright: Hundsun
 */
(function($) {
	$.fn.next = function(){
		var node  = null;
		var _nodeType = null;
		if($(this)[0] && $(this)[0].nextSibling){
			node = $(this)[0].nextSibling;	
		}
		if(node){
			_nodeType =  node.nodeType;	
		}
		 
		while(node && _nodeType){
			if(_nodeType === 1)
				break;
			node = node.nextSibling;
			_nodeType =  node.nodeType;
		}
		if(!node){
			return null;
		}
		return $(node);	 
	};
	$.fn.previous = function(){
		var node  = null;
		var _nodeType = null;
		if($(this)[0] && $(this)[0].previousSibling){
			node = $(this)[0].previousSibling;	
		}
		if(node){
			_nodeType =  node.nodeType;	
		}
		 
		while(node && _nodeType){
			if(_nodeType === 1)
				break;
			node = node.previousSibling;
			_nodeType =  node.nodeType;
		}
		if(!node){
			return null;
		}
		return $(node);	
	}
	$.fn.nextNode = function(){
		var next = $(this)[0].nextSibling;
		return $(next);
	}
	$.fn.renderSelectBox = function(){
		var container = $("#jqmobiSelectBoxContainer");
		container.removeAttr("style");
		container.addClass("selected_box");
		 
		var selectBoxHeader = $("#jqmobiSelectBoxHeader",container);
	  selectBoxHeader.removeAttr("style");
		selectBoxHeader.addClass("select_box_title");
	 
		var selectRow =$(".jqmobiSelectRow",container);
		selectRow.removeAttr("style");
		selectRow.addClass("jqmobiSelectRow");
	  
	};
	$.fn.fixSelectBox = function(){
		var activeId = $.ui.activeDiv.id;
		$.selectBox.getOldSelects(activeId);
	}
})(jq);

(function($) {
	
	$.fn.checkAnchorClick = function(theTarget){
		var parent = false;
    if (theTarget.tagName.toLowerCase() != "a" && theTarget.parentNode)
        parent = true, theTarget = theTarget.parentNode; //let's try the parent so <a href="#foo"><img src="whatever.jpg"></a> will work
    if (theTarget.tagName.toLowerCase() == "a") {
        if (theTarget.href.toLowerCase().indexOf("javascript:") !== -1 || theTarget.getAttribute("data-ignore")) {
            return false;
        }
        
        if (theTarget.onclick && !jq.os.desktop) {
            theTarget.onclick();
        }
        
        if(theTarget.href.indexOf("tel:")===0)
           return false;
        if (theTarget.hash.indexOf("#") === -1 && theTarget.target.length > 0) 
        {
            
            if (theTarget.href.toLowerCase().indexOf("javascript:") != 0) {
                if (jq.ui.isAppMobi)
                    AppMobi.device.launchExternal(theTarget.href);
                else if (!jq.os.desktop)
                    brokerClickEventMobile(theTarget);
                else
                    window.open(theTarget);
                return true;
            }
            return false;
        }
        if ((theTarget.href.indexOf("#") !== -1 && theTarget.hash.length == 0) || theTarget.href.length == 0)
            return true;
        
        var mytransition = theTarget.getAttribute("data-transition");
        var resetHistory = theTarget.getAttribute("data-resetHistory");
        
        resetHistory = resetHistory && resetHistory.toLowerCase() == "true" ? true : false;
        
        var href = theTarget.hash.length > 0 ? theTarget.hash : theTarget.href;
        jq.ui.loadContent(href, resetHistory, 0, mytransition, theTarget);
        return true;
    }	
	}
})(jq);

 
/**
(function($) {
	$.fn.goBackClear = function(){
		var activeId = $.ui.activeDiv.id;
		$.ui.goBack();
		$("#"+activeId).remove();
	}
})(jq);
**/
 


 
	